/**
 * 详情对话框
 */
var WorksInfoDlg = {
    data: {
        activityId: "",
        projectType: "",
        playerId: "",
        userName: "",
        headPic: "",
        text: "",
        watch: "",
        praise: "",
        mark: "",
        status: "",
        offlineTime: "",
        handlePerson: "",
        content: "",
        handleTime: "",
        deptid: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    //admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/works/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('worksForm', result.data);

    //初始化图片
    var graphicList = result.data.graphicList;
    console.log(graphicList)
    if(null!=graphicList && graphicList.length>0){
        for(var i=0;i<graphicList.length;i++){
            var img = graphicList[i].img;
            $("#pic_big").append('<img  src="'+Feng.ctxPath+img+'" width="100px" height="100px" layer-src="'+Feng.ctxPath+img+'" alt="'+i+'" >');
        }
    }else {
        $("#pic_big").append('<p style="text-align:  center"> 暂无图片</p>');
    }

    form.render();
    layer.photos({
        photos: '#pic_big'
        ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/works/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });

    if(result.data.projectType=="2"){
        $("#isRewardBox").css("display",'block')
        if(result.data.sort>0){
            $("#sort").css("disabled","disabled")
        }
    }else {
        $("#isRewardBox").css("display",'none')
    }
    /**
     *是否中奖的开关
     */
    form.on('switch(isReward)', function(data){
        console.log(data.elem); //得到checkbox原始DOM对象
        console.log(data.elem.checked); //开关是否开启，true或者false
        console.log(data.value); //开关value值，也可以通过data.elem.value得到
        console.log(data.othis); //得到美化后的DOM对象
        if(!data.elem.checked){
            data.elem.val(0)
        }
    });

});